<?php

namespace app\api\model;

use think\Model;
use traits\model\SoftDelete;

class Parents extends Model
{
    use SoftDelete;
    protected $deleteTime = 'deletetime';
    protected $hidden = ['deletetime', 'createtime', 'updatetime'];

    public static function getByPhone($phone)
    {
        return self::with(['relations', 'parentStudent'])->where('phone', $phone)->find();
    }

    public function parentStudent()
    {
        return $this->belongsToMany(Students::class, 'parent_students', 'student_id', 'parent_id');
    }

    public function friends()
    {
        return $this->hasMany(Friends::class, 'parent_id', 'id');
    }

    public function relations()
    {
        return $this->hasOne(Relation::class, 'id', 'relation_id');
    }
}
